package com.jt.tenant.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.adapter.FreewayDetailAdapter;
import com.jt.tenant.conn.GetFreeWayDetail;
import com.jt.tenant.dialog.TipDialog;
import com.jt.tenant.widget.Tools;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/2/2.
 */
public class FreeWayDetailAcitity extends JTActivity implements View.OnClickListener {

    private TextView title_name;

    private TextView tv_order_mileage,tv_order_station,tv_order_time;

    private ListView mListView;

    private TextView freeway_order_pay;

    private FreewayDetailAdapter mAdapter;

    private String order_id,meilage,station,date,flag;

    private long time;

    private List<GetFreeWayDetail.DetailItem> detailList = new ArrayList<>();

    private GetFreeWayDetail getFreeWayDetail = new GetFreeWayDetail(new AsyCallBack<GetFreeWayDetail.Info>(){

        @Override
        public void onSuccess(String toast, int type, GetFreeWayDetail.Info info) throws Exception {

            super.onSuccess(toast, type, info);

            if(info.msg.equals("000")){

                detailList.clear();

                detailList.addAll(info.detailItemList);

                mAdapter.notifyDataSetChanged();

            }else {

                UtilToast.show(context,info.msg);

            }
        }

    });


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_freeway_detail);

        order_id = getIntent().getStringExtra("id");

        meilage = getIntent().getStringExtra("meilage");

        station = getIntent().getStringExtra("station");

        time = getIntent().getLongExtra("time",0);

        flag = getIntent().getStringExtra("flag");

        if(time/60>0){

            date = time/60+"小时"+time%60+"分";

        }else {

            date = String.valueOf(time)+"分";

        }

        init_view();

    }


    private void init_view() {

        (title_name = (TextView) findViewById(R.id.tv_title_name)).setText("高速订单");

        freeway_order_pay = (TextView)findViewById(R.id.freeway_order_pay);

        if(flag.equals("0")){

            freeway_order_pay.setVisibility(View.GONE);

        }else {

            freeway_order_pay.setOnClickListener(this);

        }

        tv_order_mileage = (TextView)findViewById(R.id.tv_order_mileage);

        tv_order_mileage.setText(Tools.F_num(meilage)+"公里");

        tv_order_station = (TextView)findViewById(R.id.tv_order_station);

        tv_order_station.setText(station+"个");

        tv_order_time = (TextView)findViewById(R.id.tv_order_time);

        tv_order_time.setText(date);

        mListView = (ListView) findViewById(R.id.freeway_list);

        mAdapter = new FreewayDetailAdapter(this,detailList);

        mListView.setAdapter(mAdapter);

        getFreeWayDetail.order_num = order_id;

        getFreeWayDetail.execute(this);

    }

    @Override
    public void onClick(View view) {

        super.onClick(view);

        switch (view.getId()){

            case R.id.freeway_order_pay:

                TipDialog tipDialog = new TipDialog(this);

                tipDialog.setType(0);

                tipDialog.setTip("订单已支付完成");

                tipDialog.show();

//                startActivity(new Intent(context,GSPaymentActivity.class)
//
//                        .putExtra("goodsname","轨迹收费系统")
//
//                        .putExtra("expand","费用支付")
//
//                        .putExtra("total_price","24")
//
//                );

                break;


        }
    }
}

